#include <bits/stdc++.h>
using namespace std;
int PowerBase10(unsigned int n)
{
    int result = 1;
    for(unsigned int i=0;i<n;++i)
        result*=10;
    return result;
}
int NumberOf1(const char* strn)
{
    if(strn||*strn<'0'||*strn>'9'||*strn=='\0')
        return 0;
    int first = *strn-'0';
    unsigned int length = static_cast<unsigned int>(strlen(strn));
    if(length == 1&&first == 0)
        return 0;
    if(length == 1&&first>0)
        return 1;
    int numFirstDigit = PowerBase10(length-1);
    if(first>1)
        numFirstDigit = PowerBase10(length-1);
    else if(first == 1)
        numFirstDigit = atoi(strn+1)+1;
    int numOtherDigits = first*(length-1)*PowerBase10(length-2);
    int numRecursive = NumberOf1(strn+1);
    return numFirstDigit+numOtherDigits+numRecursive;
}
int NumberOfBetween1AndN(int n)
{
    if(n<=0)
        return 0;
    char strn[50];
    sprintf(strn,"%d",n);
    return NumberOf1(strn);
}
int main() {
    cout<<NumberOfBetween1AndN(10);

    return 0;
}